#@adminLayout()

#define main()
  <main class="app-content">
    <div class="app-title">
      <div>
        <h1><i class="fa fa-th-list"></i>正在为 <span style="color: red;">#(role.name)</span> 分配权限</h1>
        <p>点亮左侧开关分配权限给当前角色</p>
      </div>
      <ul class="app-breadcrumb breadcrumb">
        <li class="breadcrumb-item"><a href="/admin"><i class="fa fa-home fa-lg"></i>仪表盘</a></li>
        <li class="breadcrumb-item active"><a href="/admin/role">权限管理</a></li>
        <li class="breadcrumb-item active"><a href="javascript:;">权限分配</a></li>
      </ul>
    </div>

	#set(n = 0)
		#for(mapItem : permissionMap)
			#if(n % 2 == 0)<div class="row">#end
				#@printTable()
				#set(n = n + 1)
				#if(n % 2 == 0)</div>#end
			#end
  </main>
#end

#define printTable()
<div class="col-md-6">
   <div class="tile">
     <table class="table table-bordered">
       <thead>
         <tr></tr>
       </thead>
       <tbody>
       #for(x : mapItem.value)
         <tr>
           <td>
				<div class="toggle lg"><label>
					<input data-role-id="#(role.id)"
					   data-permission-id="#(x.id)"
					   #if(x.assigned) checked #end
					   type="checkbox" class="mgc-switch mgc-tiny">
				<span class="button-indecator"></span></label>
  				</div>
           </td>
           <td>#(x.remark)</td>
         </tr>
        #end
       </tbody>
     </table>
   </div>
</div>
#end
#define js()

<script type="text/javascript">
	$(document).ready(function() {
		initMagicInput(prepareAction);
	});

	function prepareAction($this, state) {
		return {
			url: state ? "/admin/role/addPermission" : "/admin/role/deletePermission",
			data : {
				roleId: $this.data("role-id"),
				permissionId: $this.data("permission-id")
			}
		}
	}
</script>
#end